﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;
namespace InterfaceView
{
    public partial class LoginView : CCSkinMain
    {
        public LoginView()
        {
            InitializeComponent();
        }
        static Random rd = new Random();
        static string rnum = Convert.ToString(rd.Next(1000, 10000));

        public bool ValidateInput()
        {
            if(this.textBox1_username.Text.Length == 0 || this.textBox2_userpwd.Text.Length == 0)
            {
                MessageBox.Show("UserName and Password can not empty!");
                this.textBox1_username.Focus();
                return false;
            }
            return true;
        }

        private void button1_login_Click_1(object sender, EventArgs e)
        {
            if (this.skinTextBox2_code.Text != rnum)
            {
                MessageBox.Show("Identifying Code Error !");
            }
            else
            {
                if (ValidateInput())
                {
                    string userName = this.textBox1_username.Text;
                    string userPwd = this.textBox2_userpwd.Text;
                    if (BusinessLogic.Login.LoginUser(userName, userPwd))
                    {
                        this.Hide();
                        //Operation operation = new Operation();
                        //operation.Show();
                        Select select = new Select();
                        select.Show();
                    }
                    else
                    {
                        this.textBox1_username.Text = "";
                        this.textBox2_userpwd.Text = "";
                        this.textBox1_username.Focus();
                    }
                }
            }
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Identifying Code have sent , Please wait for moment!");
            string secret = "66ab455b94bd30f9df7cd1636c2a81d1";
            string url = @"http://gw.api.taobao.com/router/rest";
            string appkey = "23285482";
            ITopClient client = new DefaultTopClient(url, appkey, secret);
            AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
            req.Extend = "123456";
            req.SmsType = "normal";
            req.SmsFreeSignName = "章氏国际酒店";
            //Random rd = new Random();
            //string rnum =Convert.ToString(rd.Next(1000, 10000));
            req.SmsParam = "{\"code\":\""+rnum+"\",\"product\":\"Zhang International Hotel of ManagerMent\"}";
            string phoneNum = this.skinTextBox1_phone.Text;
            req.RecNum = phoneNum;
            req.SmsTemplateCode = "SMS_3450196";
            AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req);
            Console.WriteLine(rsp.Body);
        }

        private void LoginView_Load(object sender, EventArgs e)
        {
           
        }






    }
}
